package com.cxl.asynctask;

import java.io.IOException;
import java.net.Socket;

import android.os.AsyncTask;

import com.cxl.AppConstant;
import com.cxl.model.Instruction;

public class MouseAsyncTask extends AsyncTask<Integer, Void, Void>{

	Socket socket;
	int moveX, moveY;	
	public MouseAsyncTask(Socket socket) {
		super();
		this.socket = socket;
	}

	
	public MouseAsyncTask(Socket socket, int moveX, int moveY) {
		super();
		this.socket = socket;
		this.moveX = moveX;
		this.moveY = moveY;
	}


	@Override
	protected Void doInBackground(Integer... params) {
		// TODO Auto-generated method stub
		if(params[0] == AppConstant.MOUSEMOVE){
			try {
				System.out.println("moveX and moneY--->"+ moveX +"   " +moveY);
				socket.getOutputStream().write(new Instruction(params[0], moveX, moveY, 0, 0, 0, 0).byteBuf);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(params[0] == AppConstant.GETMOUSE || params[0] == AppConstant.LEFTMOUSECLICK ||
				params[0] == AppConstant.RIGHTMOUSECLICK ){
			try {
				socket.getOutputStream().write(new Instruction(params[0], 0, 0, 0, 0, 0, 0).byteBuf);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println("doinback thread---->" + Thread.currentThread().getId());
		return null;
	}



}
